package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.Appointment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AppointmentMapper extends BaseMapper<Appointment> {

    /**
     * 查询指定医生在指定时间段内的预约记录，如果doctorId为null则查询所有医生的预约
     * @param doctorId 医生ID，可为null
     * @param startTime 起始时间字符串，格式：yyyy-MM-dd HH:mm:ss
     * @param endTime 结束时间字符串，格式：yyyy-MM-dd HH:mm:ss
     * @return 预约列表
     */
    @Select("<script>" +
            "SELECT * FROM appointment " +
            "WHERE appointment_time BETWEEN #{startTime} AND #{endTime} " +
            "<if test='doctorId != null'> AND doctor_id = #{doctorId} </if> " +
            "ORDER BY appointment_time DESC" +
            "</script>")
    List<Appointment> selectTodayAppointments(@Param("doctorId") Integer doctorId,
                                              @Param("startTime") String startTime,
                                              @Param("endTime") String endTime);
}
